<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        // new自定义的构造函数()
        //定义构造函数，并且设置属性和方法
        function fn() {
            this.age = 40;
            this.say = function() {
                return 'hello';
            }
        }

        var obj2 = new fn(); //实例化构造函数fn，得到对象
        console.log(obj2, typeof obj2);
        console.log(obj2.say());
    </script>
</body>

</html>